import os
import sys


def rename(path, old, new):
    files = os.listdir(path)

    for file in files:
        dir = os.path.join(path, file)
        # 检测是否为文件夹，如果是，则递归
        if os.path.isdir(dir):
            rename(dir, old, new)
            continue
        file = file.replace(old, new)
        new_dir = os.path.join(path, file)
        try:
            os.rename(dir, new_dir)
        except:
            pass


def add_pre(path, pre):
    files = os.listdir(path)

    for file in files:
        dir = os.path.join(path, file)
        # 检测是否为文件夹，如果是，则递归
        if os.path.isdir(dir):
            add_pre(dir, pre)
            continue
        file = pre + file
        new_dir = os.path.join(path, file)
        os.rename(dir, new_dir)


if __name__ == '__main__':
    path = sys.argv[1]
    # old = sys.argv[2]
    # new = sys.argv[3]
    # rename(path, old, new)
    pre = sys.argv[2]
    add_pre(path, pre)
